<?php

vendor('simple_raw_storage');

class Blob extends AppModel implements SimpleRAWStorage
{

	public $name = 'Blob';

	public $displayField = 'id';

	public $validate = array(
	);

	public $hasOne = array(
		'Reporting' => array('className' => 'Reporting',
            'dependent' => false,
        ),
	);

	function allowDelete($fields = null)
	{
	    if (!isset($fields)) {
	        return true;
	    }
	    if (empty($fields[$this->primaryKey])) {
	        return false;
	    }
        $this->Reporting->rel();
        return ! is_array($this->Reporting->find(array("`".Inflector::underscore($this->name)."_id`" => $fields[$this->primaryKey])));
	}

	function allowUpdate($fields = null)
	{
        return false;
	}

    /**
     * Возвращает содержимое по его идентификатору.
     *
     * @param int $id
     *
     * @return string
     */
    function getDataById($id)
    {
        if (! is_numeric($id)) {
            throw new ArgException();
        }
        $id = intval($id);
        if (empty($id)) {
            throw new ArgException();
        }
        $this->rel();
        $result = $this->field("data", array("`{$this->name}`.`{$this->primaryKey}`" => $id));
        if (empty($result)) {
            $result = '';
        }

        return $result;
    }
}

?>